package com.abing.starry.strategy.api;

import com.abing.api.client.StarryApiClient;
import com.abing.api.model.StarryApiRequest;
import com.abing.starry.common.ErrorCode;
import com.abing.starry.exception.ThrowUtils;
import lombok.RequiredArgsConstructor;
import org.apache.commons.lang3.StringUtils;

/**
 * @Author CaptainBing
 * @Date 2024/8/24 22:08
 * @Description
 */
@RequiredArgsConstructor
@InvokeStrategyConfig(strategy = InvokeStrategyEnum.STARRY)
public class StarryInvokeStrategy implements InvokeStrategy {

    private final StarryApiClient starryApiClient;

    @Override
    public String doInvoke(StarryApiRequest starryApiRequest) {
        String url = starryApiRequest.getUrl();
        String method = starryApiRequest.getMethod().toUpperCase();
        ThrowUtils.throwIf(StringUtils.isAnyEmpty(url, method), ErrorCode.PARAMS_ERROR);
        return starryApiClient.starryApiSend(starryApiRequest);
    }
}


